package map.blocks;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import map.MapObject;
import map.PlayerObject;
import map.RasterCell;

public class ImageBasedBlock extends MapObject {

	private transient BufferedImage img;
	private String imageSource;
	
	public ImageBasedBlock(String imageSource) {
		this.imageSource = imageSource;
		try {
			img = ImageIO.read(new File(imageSource));
		} catch (IOException e) {
			System.err.println("Error while reading image: " + imageSource);
			e.printStackTrace();
		}	
	}
	
	public ImageBasedBlock(BufferedImage img){
		//img.
		this.imageSource = "default.png";
	}

	@Override
	public boolean interact(PlayerObject actor) {
		return false;
	}

	@Override
	public boolean entered(PlayerObject actor) {
		return false;
	}

	@Override
	public void paintComponent(Graphics arg0, RasterCell target) {
		arg0.drawImage(img, target.getCx()*target.RASTERSIZE, target.getCy()*target.RASTERSIZE, null);
	}

	@Override
	public void deseriralize() {
		try {
			img = ImageIO.read(new File(imageSource));
		} catch (IOException e) {
			System.err.println("Error while reading image: " + imageSource);
			e.printStackTrace();
		}
	}

	@Override
	public MapObject newInstance() {
		// TODO Auto-generated method stub
		return null;
	}

}
